/**
 * SPDX-FileCopyrightText: 2023-2025 Sangfor Technologies Inc.
 * SPDX-License-Identifier: Mulan PSL v2
 */

<template>
    <div class="feature-operate-step__container">
        <div class="operate-step__list">
            <div v-for="(item,index) in operateList" 
                 :key="item.id"
                 class="operate-step__item"
                 :class="{'active':index===activeIndex-1}"
                 @click="_operatePreview (index)">
                <div class="operate__step">
                    Step {{ index+1 }}
                </div>
                <div class="operate__box">
                    <div class="operate-content">
                        <div class="operate__img"
                             :class="operateImg(item.img)"></div>
                        <div class="operate__name">
                            {{ item.name }}
                        </div>
                    </div>
                    <div class="operate__opr">
                        <i 
                            class="icon iconfont"
                            :class="index === operateList.length - 1 ? 'iconbianji1' : 'iconchakanxiangqing'"
                            @click="_editOperate($event,item,index)"></i>
                        <i v-if="index === operateList.length - 1"
                           class="icon iconfont iconshanchu1"
                           @click="_deleteOperate($event,item,index)"></i>
                    </div>
                </div>
            </div>
            <div class="remove-operate-step">
                <sf-button
                    class="btn-blank"
                    icon-cls="iconqingkong"
                    @click="_deleteOperateStep">
                    <lang>清空所有步骤</lang>
                </sf-button>
            </div>
        </div>
    </div>
</template>
<script>

// import {isFunction} from 'src/util/typeof';

import {COMPONET_MARK} from 'src/home/mod_cluster/project_manager/feature_manager/const_data';
export default {
    name: 'OperateStep',
    props: {
        stepList:{
            default:()=>[],
            type:Array
        },

        //算子的active下标
        activeIndex:{
            default:0,
            type:Number
        }
    },

    data () {
        return {
            operateLayer: null,
            fieldList:[]
        };
    },

    computed: {
        operateList () {
            if (this.stepList.length) {
                let list = [];

                //只取后边几步第一步不要
                let stepList = this.stepList.slice(1);
                stepList.forEach(item=>{
                    list.push(Object.assign({
                        formData:item.params
                    }, COMPONET_MARK[item.type]));
                });
                return list;
            }
            return [];
        }
    },
    methods: {

        //编辑算子
        _editOperate (e, item, index) {

            //阻止预览
            /*eslint-disable*/
            e.stopPropagation();
            let previewFlag = index !== this.operateList.length - 1;
            this.$emit('operate-edit', e, item, index + 1 , previewFlag);
        },

        //删除步骤
        _deleteOperate (e,item,index) {

            //阻止预览
            /*eslint-disable*/
            e.stopPropagation();
            this.$confirm({
                title: _('提示'),
                subTitle: _('确定要删除该{0}步骤吗？',item.name),
                msg: '',
                icon: 'warning',
                autoClose: true,
                callback: actionName => {
                    if (actionName === 'submit') {
                        this.$emit('operate-delete', index + 1);

                        // this.ajaxDeleteOperate(record);
                    }
                }
            });
        },
        _deleteOperateStep(){
            this.$emit('all-step-delete');
        },
        operateImg (type) {
            return `img-${type}`;
        },

        //预览算子
        _operatePreview (index) {
            this.$emit('operate-preview', index + 1);
        }
    }
};
</script>

<style lang="less">
    .feature-operate-step__container{
        height: calc(100% - 126px);
        margin: 0 8px;
        .remove-operate-step{
            text-align: center;
            margin-top:-10px;
            .sfv-btn.btn-blank{
                background: #F5F7FA;
                color: #c2c2c2;
                border: 1px solid #ddd;
                
            }
            .btn-blank{
                &:hover{
                    background-color: #e8f0ff;
                    color: #36f;
                    border-color: #36f;
                }
            }
            
        }
        .operate-step__list{
        height: 100%;
        overflow: auto;
        border-bottom: 1px solid #DEE3ED;
        padding-bottom: 10px;
    }
    
    .operate-step__item{
        width:182px;
        margin:10px auto;
        font-size: 14px;
        color: #14161A;
        margin-bottom: 20px;
        cursor: pointer;
        &.active{
            .operate__box{
                border: 2px solid #3366FF;
            }
        }
        .operate__step{
            margin-bottom: 8px;
            position: relative;
            padding-left: 5px;
            &:before{
                content: '';
                background: #204ED9;
                width: 4px;
                height: 4px;
                transform: rotate(45deg);
                position: absolute;
                left: -5px;
                top: 8px;
            }
        }
        .operate__box{
            width: 182px;
            height: 48px;
            margin: 0 auto;
            border: 1px solid #C8D0E0;
            border-radius: 2px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            background: #fff;
            &:hover{
                border: 2px solid #3366FF;
            }
            .operate-content{
                margin-left: 12px;
                display: flex;
                align-items: center;
            }
            .operate__opr{
                margin-right: 8px;
                position: relative;
                &:before{
                    content: '';
                    background: #D8D8D8;
                    width:1px;
                    height:12px;
                    position: absolute;
                    left: -8px;
                    top: 5px;
                }
                .iconfont{
                    &:hover{
                        color: #3366FF;
                    }
                }
                .iconshanchu1{
                    margin-left: 2px;
                }
            }
        }
        .operate__img{
            width: 24px;
            height: 24px;
            margin-right: 4px;
            &.img-agg{
                background: url(../../img/agg.svg) no-repeat;
                background-size:100% 100%;
            }
            &.img-filter{
                background: url(../../img/filter.svg) no-repeat;
                background-size:100% 100%;
            }
            &.img-opr{
                background: url(../../img/opr.svg) no-repeat;
                background-size:100% 100%;
            }
            &.img-timeStamp{
                background: url(../../img/timeStamp.svg) no-repeat;
                background-size:100% 100%;
            }
            &.img-smooth{
                background: url(../../img/smooth.svg) no-repeat;
                background-size:100% 100%;
            }
            &.img-stringOpr{
                background: url(../../img/stringOpr.svg) no-repeat;
                background-size:100% 100%;
            }
            &.img-timeSeries{
                background: url(../../img/timeSeries.svg) no-repeat;
                background-size:100% 100%;
            }
            &.img-outlier{
                background: url(../../img/outlier.svg) no-repeat;
                background-size:100% 100%;
            }
        }
        
    }
    }
    
    .operate__layer {
        // left: 426px !important;
        .operate_form__title{
            padding: 16px 16px 0 16px;
            font-size: 14px;
        }
        .add-operate__btn {
            border-top: 1px solid #ddd;
            padding: 8px;
            background-color: #fdfdfd;
            text-align: right;
        }
        .operate_form {
            .sfv-form{
                padding: 16px 16px 10px 22px;
                /* margin-bottom:15px; */
            }
            .form__title{
                font-size: 14px;
                color: #222D3D;
                font-weight:700;
            }
            .form-item--first {
                margin-bottom: 16px;
            }
            .align-center{
                display: flex;
                align-items: center;
            }
            .sfv-form-item {
                .sfv-fieldlabel {
                    color: #5C5C5C;
                }

                .sfv-fieldlabel-left {
                    padding-left: 0;
                }
            }

            .form-item__title  {
                display: block;
                font-size: 13px;
                color: #222D3D;
                margin-bottom: 12px;
                font-weight: bold;
            }
        }
            .add-condition__btn {
            border-top: 1px solid #ddd;
            padding: 8px;
            background-color: #fdfdfd;
            text-align: right;
        }
    }
  
    /* .component-tree-title{
        display: flex;
        align-items:center;
        font-size:16px;
        color: #1F1F1F;
        padding-left:20px;
        height: 48px;
        border-bottom:1px solid #ddd;
        font-weight:600;
    } */
</style>


